#include "a.h"

A::A()
{
    qDebug()<<"insideClass"<<registerNativeMthode();//放在这就崩了
    qDebug()<<"insideNewClass"<<registerNativeMthode2();//没注册就用果然
    QAndroidJniObject stra=QAndroidJniObject::fromString("ririri");//构造Java的String对象
    jint inttyp=1;
    jfloat floatJ[3];
//    jfloat gg[3];
    floatJ[0]=1.3;
    floatJ[1]=1.3;
    floatJ[2]=1.3;
    float *SS=floatJ;
//    gg[]=floatJ[] ;
    QAndroidJniObject jh("an/qt/hello/JHello","(Ljava/lang/String;)V",stra.object<jstring>());//注意.object()，构造Java对象
//    QAndroidJniObject jh("an/qt/hello/JHello","(Ljava/lang/String;)V",stra.object());//注意.object()暂时都可以
    QAndroidJniObject restr=jh.callObjectMethod("reHello","(I)Ljava/lang/String;",inttyp);//对象调用方法
    jint staticf=QAndroidJniObject::callStaticMethod<jint>("an/qt/hello/JHello","reintlou","(I)I",inttyp);//注意<jint>  jint 匹配，调用静态方法
    QAndroidJniObject staticf2=QAndroidJniObject::callStaticObjectMethod("an/qt/hello/JHello","reintlou2","(I)Ljava/lang/String;",inttyp);
    QAndroidJniObject path=QAndroidJniObject::callStaticObjectMethod("an/qt/hello/JHello","returnSdcardPath","()Ljava/lang/String;");//
//    jstring path2=QAndroidJniObject::callStaticMethod<jstring>("an/qt/hello/JHello","returnSdcardPath","()Ljava/lang/String;");
//    jstring path3=QAndroidJniObject::fromString("ASD");这也不行
//    jstring要用callStaticObjectMethod
//    注意返回值类型不能是基础类型
    qDebug()<<restr.toString();
    qDebug()<<staticf;
    qDebug()<<staticf2.toString();
    qDebug()<<"path:"+path.toString();
//    qDebug()<<stra;//直接打印不行
    int qtint=inttyp;
//    float qtfloat=floatJ;
    qDebug()<<"Asd:"<<qtint<<"  "<<SS[2];
//    qDebug()<<"insideClass"<<registerNativeMthode();//放在这就崩了
//    qDebug()<<"insideNewClass"<<registerNativeMthode2();//没注册就用果然

    //修改QtActivity测试(采集方向值OK，修改了原QtActivity)

    testTimer.setInterval (5000);
    testTimer.setSingleShot (false);
    connect (&testTimer,SIGNAL(timeout()),this,SLOT(testFanxianzhi()));
    testTimer.start ();

}


void A::testFanxianzhi (){
    //修改QtActivity测试(采集方向值OK，修改了原QtActivity)
    QAndroidJniObject rootQA=QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/bindings/QtActivity","returnThis","()Lorg/qtproject/qt5/android/bindings/QtActivity;");//返回自身的静态函数
    QAndroidJniObject of=rootQA.callObjectMethod("calculateOrientation","()[F");
    jfloatArray tempOF=of.object<jfloatArray>();
    QAndroidJniEnvironment qjniEnv;
    float *SS=qjniEnv->GetFloatArrayElements(tempOF,false);//看Jni.h按F2向上寻找可得，也可百度数组处理方法
    qDebug()<<qRadiansToDegrees(SS[0])<<"  "<<qRadiansToDegrees(SS[1])<<"  "<<qRadiansToDegrees(SS[2])<<"  ";
}
